package com.ykg.controller;

import com.ykg.annotation.PassToken;
import com.ykg.dto.UnloadShipDTO;
import com.ykg.enums.ResultEnum;
import com.ykg.interceptor.ScopeLevel;
import com.ykg.pojo.Entrust;
import com.ykg.service.IUnloadShipService;
import com.ykg.util.ResultResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

/**
 * TODO
 * 类(接口)：
 * Created on 8:19 2021/6/26.
 *
 * @Author: laobian
 * @Description:
 */
@Api(tags = "卸船作业部Api")
@RestController
@RequestMapping("/api/unload")
public class UnloadController {

    @Autowired
    private IUnloadShipService unloadShipService;

    //@PassToken
    @ApiOperation("获得卸货清单")
    @GetMapping("/unloadList")
    @ScopeLevel(value = 6)
    public ResultResponse findAllList(){
        List<Entrust> entrusts = unloadShipService.getEntrustUnload();
        if(Objects.isNull(entrusts)){
            return  new ResultResponse(ResultEnum.PARAM_ERROR);
        }
        return new ResultResponse(entrusts);
    }

    //@PassToken
    @ApiOperation("获得卸货清单详情")
    @GetMapping("/unload/{entrustId}")
    @ScopeLevel(value = 6)

    public ResultResponse findUnloadInfo(@PathVariable(value = "entrustId") String entrustId){
        if(entrustId == null){
            return  new ResultResponse(ResultEnum.PARAM_ERROR);
        }
        UnloadShipDTO unloadShipDTO = unloadShipService.getEntrustUnloadDetailed(entrustId);
        if(Objects.isNull(unloadShipDTO)){
            return  new ResultResponse(ResultEnum.FAILURE);
        }
        return new ResultResponse(unloadShipDTO);
    }

    //@PassToken
    @ApiOperation("完成卸货清单")
    @PostMapping("/unload/finish")
    @ScopeLevel(value = 6)

    public ResultResponse updateUnload(@RequestParam String entrustId){
        if(entrustId == null){
            return  new ResultResponse(ResultEnum.PARAM_ERROR);
        }
        int status = unloadShipService.finishUnload(entrustId);
        if(Objects.isNull(status)){
            return  new ResultResponse(ResultEnum.FAILURE);
        }
        return new ResultResponse(ResultEnum.SUCCESS);
    }




}
